/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.cqq.announcement;

import com.yunhoo.cqq.model.Document;
import com.yunhoo.sys.util.common.FacesUtils;
import java.util.List;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import org.richfaces.event.FileUploadEvent;

/**
 * 
 * @author hongli
 */
public class ModifyAnnounceTypeBean {

    private boolean showAble = true;
    private boolean addOrUpdate = false;
    private Document document;
    private List documentlist;
    private UIData data = null;
    private UIData data1 = null;
    private String dispMessage;
    private String fileName;
    private String filePath;
    private String serverUrl;
    private String strVal;

    /** Creates a new instance of DocumentBean */
    public ModifyAnnounceTypeBean() {
//        document = new Document();
        showAble = true;
        addOrUpdate = false;
        }

    public List getDocumentlist() {
        return documentlist;
    }

    public String getStrVal() {
        return strVal;
    }

    public void setStrVal(String strVal) {
        this.strVal = strVal;
    }

    public void getVal(){
    System.out.println(strVal+"+++");
    }
    
    public String getServerUrl() {
        HttpServletRequest request = FacesUtils.getServletRequest();
        serverUrl = "http://" + request.getRemoteHost() + ":" + request.getServerPort() + request.getContextPath() + "/uploadResources/";
        return serverUrl;
    }

    public void setServerUrl(String serverUrl) {
        this.serverUrl = serverUrl;
    }

    /**
     * 根据该用户得到所有具备查看权限的文件
     * @return
     */
    public List getDocumentlistByUser() {
        if (documentlist == null) {
            document = new Document();
//            return type.getAllList("document");
            FacesContext fc = FacesContext.getCurrentInstance();
//            AccountBean accountBean = (AccountBean) fc.getExternalContext().getSessionMap().get("account");
//            Account account = accountBean.getAccount();
//            List<Document> list=type.getGenFourListByObject(account, "document");
//            for(Document document:list){
//            System.out.println(document.getUrl()+"--------");
//            }
//            return type.getGenFourListByObject(account, "document");
        }
        return documentlist;
    }

    /**
     * 按文档名称检索
     */
    public void search() {
        FacesContext fc = FacesContext.getCurrentInstance();
        ModifyAnnounceTypeBean docBean = (ModifyAnnounceTypeBean) fc.getExternalContext().getSessionMap().get("document");
//        AccountBean accountBean = (AccountBean) fc.getExternalContext().getSessionMap().get("account");
//        Account account = accountBean.getAccount();
//        User user = new User();
//        user.setUid(account.getCode());
//        user.setUname(account.getAdmin());
//        user.setUpw(account.getPw());

        Document document = docBean.getDocument();
        document.setTitle(document.getTitle().trim());
//        DocumentUser docUser = new DocumentUser();
//        docUser.setDocument(document);
//        docUser.setUser(user);

//        documentlist = type.getGenThirdListByObject(docUser, "document");
    }


    public void uploadListener(FileUploadEvent event) {
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getDispMessage() {
        return dispMessage;
    }

    public void setDispMessage(String dispMessage) {
        this.dispMessage = dispMessage;
    }

    public boolean isAddOrUpdate() {
        return addOrUpdate;
    }

    public void setAddOrUpdate(boolean addOrUpdate) {
        this.addOrUpdate = addOrUpdate;
    }

    public UIData getData() {
        return data;
    }

    public void setData(UIData data) {
        this.data = data;
    }

    public UIData getData1() {
        return data1;
    }

    public void setData1(UIData data1) {
        this.data1 = data1;
    }

    public Document getDocument() {
        return document;
    }

    public void setDocument(Document document) {
        this.document = document;
    }

    public void setDocumentlist(List documentlist) {
        this.documentlist = documentlist;
    }

    public boolean isShowAble() {
        return showAble;
    }

    public void setShowAble(boolean showAble) {
        this.showAble = showAble;
    }

}
